package com.dd.keel.core.common.shutdown.protocol;

/**
 * protocol message based on state.
 * @author Kevin.XU
 *
 */

public class ShutdownProtocol implements Protocol{
	
    public static final int WAITING = 0;
    public static final int SENTBYE = 2;
    
    private int state = WAITING;
	
    final public static String SHUTDOWN_REQUEST_MESSAGE = "aiip*llama*shutdown";
    
	public String processInput(String theInput) {
		String theOutput = "...........................";
		if (state == WAITING && SHUTDOWN_REQUEST_MESSAGE.equals(theInput) ) 
		{
			theOutput = "I am doing shutdown myself...";
			state = SENTBYE;
		}
		else if( state == SENTBYE )
		{
			theOutput = "Done!";
			state = SENTBYE;
		}
		return theOutput;
	}
	
	public int getState()
	{
		return state;
	}

}
